<?php 
    $more=array();
    //var_dump($_SESSION);die;
    //$total=0;
    //$total_confirm=0;
?>
<div class="main clearfix">

    <div class="box clearfix bottom30">
        <form action="" method="get">
            <ul class="form4">
                <li class="clearfix"><label><strong>Năm </strong>:</label>
                    <div class="filltext">
                        <select id="year" name ="year">
                            <?php $now = date("Y");for($i=$now;$i >= 2010;$i--){ ?>
                                <option value="<?php echo $i;?>"  <?php if(isset($year)){if($year==$i){echo "selected='selected'";}} ?> ><?php echo  "Năm ".$i;?></option>
                                <?php } ?>
                        </select>
                    </div>
                </li>
                <li class="clearfix"><label><strong>Tài khoản </strong>:</label>
                    <div class="filltext">
                        <input type="text" name="username" value="<?php if(isset($username)){echo $username; } ?>" style="width:331px;margin-right:28px">
                    </div>
                </li>


                <li class="clearfix"><label>&nbsp;</label>
                    <div class="filltext">
                        <input type="submit" class="btn-bigblue" value=" Tìm kiếm"> 
                    </div>
                </li>
                <li>
                    <?php if(!empty($error)) { ?>
                        <div class="err_log txt-left mag-btt10">
                            <p style="color: red" class="clf60 s14"><strong>Thông báo:</strong> <?php echo $error;?></p>
                        </div>
                        <?php } ?>
                </li>
            </ul>
        </form>
    </div>
    <div class="box">
        <div class="table">
            <table width="100%" cellspacing="0" cellpadding="0" border="0">
                <tbody>
                    <tr class="bg-grey">
                        <td width="10%"><strong>Tài khoản</strong></td>
                        <td width="15%"><strong>Doanh thu sau Telco</strong></td>
                        <td width="15%"><strong>Doanh thu sau đầu số</strong></td>
                        <td width="15%"><strong>Doanh thu phát sinh Wap</strong></td>
                        <td width="15%"><strong>Đề xuất doanh thu</strong></td>
                        <td width="15%"><strong>Số dư cuối kì Wap</strong></td>
                    </tr>
                    <tr>
                        <td><strong class="clblue"><?php if(isset($username)){ echo $username;} ?></strong></td>
                        <td><strong class="clred"><?php echo Common::format_price($total_tel); ?></strong></td>
                        <td><strong class="clred"><?php echo Common::format_price($total_ds); ?></strong></td>
                        <td><strong class="clred"><?php echo Common::format_price($total); ?></strong></td>
                        <td><strong class="clred"><?php echo Common::format_price($total_confirm) ; ?></strong></td>
                        <td>
                            <strong class="clred">
                                <?php 
                                if($year==2012){
                                  echo Common::format_price($total-$total_confirm);    
                                } else {
                                  echo Common::format_price($total-$total_confirm+$wap_excess[$year][1]);    
                                }
                                
                                ?>

                            </strong>
                        </td>
                    </tr>
                </tbody>

            </table>
        </div>
    </div>
    <div class="box">
        <div class="fillter clearfix">

            <div class="fr">
                <a class="excel" href="#"><strong>Xuất ra file Excel</strong></a>

            </div>
        </div>
        <div class="table clearfix">
            <table width="100%" cellspacing="0" cellpadding="0" border="0">
                <tbody>

                    <tr class="bg-grey">
                        <td  width="13%"><strong>Chi tiết theo tháng</strong></td>
                        <?php for($i=1;$i<13;$i++){ ?>
                            <td width="7.5%"><strong>Tháng <?php echo $i; ?></strong></td>
                            <?php } ?>
                    </tr>
                    <tr>
                        <td style="text-align: left;"><strong>Số dư đầu kì Wap</strong></td>
                        <?php for($i=1;$i<13;$i++){
                            ?>
                            <td class="text-right">
                                <?php
                                    if($year== date("Y") && $i > date('m')){
                                        echo 0;
                                    } else{ 
                                        if($year==2012 && $i==1 ){
                                            $more[$i]=0; 
                                            echo $more[$i];  
                                        } else if($year!=2012 && $i==1){
                                                $more[$i]=$wap_excess[$year][1];
                                                echo Common::format_price($more[$i]);
                                            }else{
                                                $more[$i-1]=Common::format_price($total_month[$i-1]-$confirm_month[$i-1] ) ; 
                                                echo ($more[$i-1]);
                                        }
                                    }        

                                ?>
                            </td>
                            <?php } ?>
                    </tr>

                    <tr>
                        <td style="text-align: left;"><strong>Doanh thu sau Telco</strong></td>
                        <?php for($i=1;$i<13;$i++){

                            ?>
                            <td class="text-right"><?php echo Common::format_price($total_telco[$i]) ;?></td>
                            <?php } ?>

                    </tr>
                    <tr>
                        <td style="text-align: left;"><strong>Doanh thu sau đầu số</strong></td>
                        <?php for($i=1;$i<13;$i++){

                            ?>
                            <td class="text-right"><?php echo Common::format_price($total_dauso[$i]) ;?></td>
                            <?php } ?>

                    </tr>

                    <tr>
                        <td style="text-align: left;"><strong>Doanh thu phát sinh Wap</strong></td>
                        <?php for($i=1;$i<13;$i++){

                            ?>
                            <td class="text-right">
                                <?php
                                    echo  Common::format_price($total_month_show[$i]) ;
                                ?>
                            </td>
                            <?php } ?>

                    </tr>
                    <tr>
                        <td style="text-align: left;"><strong>Đề xuất doanh thu</strong></td>
                        <?php for($i=1;$i<13;$i++){

                            ?>
                            <td class="text-right"><?php echo Common::format_price($confirm_month[$i]) ?></td>
                            <?php } ?>



                    </tr>
                    <tr>
                        <td style="text-align: left;"><strong>Số dư cuối kì Wap</strong></td>
                        <?php for($i=1;$i<13;$i++){
                            ?>
                            <td class="text-right">
                                <?php
                                    if($year== date("Y") && $i > date('m')){
                                        echo 0;
                                    } else{
                                        $more[$i]=Common::format_price($total_month[$i]-$confirm_month[$i] ) ;
                                        echo $more[$i]; 
                                    } 

                                ?>
                            </td>
                            <?php } ?>
                    </tr>
                </tbody>
            </table>
        </div>


    </div>
        </div>